package com.cavy.platform.server.controller;

import com.cavy.platform.server.domain.job.JobAction;
import com.cavy.platform.server.dto.JobLogDto;
import com.cavy.platform.server.dto.JobSearchListDto;
import com.cavy.platform.server.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/{workSpace}/{project}/{pipeline}/job/")
public class JobController {

    @Autowired
    private JobService service;

    //详情
    @GetMapping("{number}")
    public JobAction info(@PathVariable String workSpace, @PathVariable String project,
                          @PathVariable String pipeline, @PathVariable String number) {
        return service.info(workSpace, project, pipeline, number);
    }

    //列表
    @GetMapping("list")
    public List<JobAction> list(@Valid JobSearchListDto dto) {
        return service.list(dto);
    }

    //获取日志
    @GetMapping("{number}/{stage}/{containerIndex}/{dependencyIndex}")
    public void log(HttpServletResponse response, @Valid JobLogDto dto) throws IOException {
        service.getLog(response, dto);
    }
}
